package academic.concordia.bankofquebec.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.Transient;

@Entity
public class Transaction implements Serializable {

	private static final long serialVersionUID = 1L;
	
	private int id;
	private UUID authorizationNumber;
	private double amount;
	private Date date;
	private TransactionType transactionType;
	private TransactionStatus status;
	private String message;
	
	public Transaction() {
		this.authorizationNumber = UUID.randomUUID();
		this.date = new Date();
		this.status = TransactionStatus.APPROVED;
	}

	@Id @GeneratedValue(strategy=GenerationType.AUTO)
	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public UUID getAuthorizationNumber() {
		return authorizationNumber;
	}

	public double getAmount() {
		return amount;
	}

	public void setAmount(double amount) {
		this.amount = amount;
	}

	public Date getDate() {
		return date;
	}

	@Enumerated(EnumType.STRING)
	public TransactionType getTransactionType() {
		return transactionType;
	}

	public void setTransactionType(TransactionType transactionType) {
		this.transactionType = transactionType;
	}

	@Enumerated(EnumType.STRING)
	public TransactionStatus getStatus() {
		return status;
	}

	public void setStatus(TransactionStatus status) {
		this.status = status;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public void setAuthorizationNumber(UUID authorizationNumber) {
		this.authorizationNumber = authorizationNumber;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	
	@Transient
	public boolean isApproved(){
		return this.status.equals(TransactionStatus.APPROVED);
	}
	
}
